package com.mall.b2c.template.directive;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.mall.b2c.bean.TagBean;
import com.mall.b2c.hessian.GoodsExtendHessian;
import com.mall.common.directive.DirectiveUtils;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

/**
 * 根据条件获取标签列表
 */
@Repository
public class TagListDirective extends BaseDirective{

	/**标签ids**/
	public static final String PARAM_IDS = "ids";
	
	@Resource 
	private GoodsExtendHessian goodsExtendHessian;
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public void execute(Environment env, Map params, TemplateModel[] loopVars,
			TemplateDirectiveBody body) throws TemplateException, IOException {
		Long[] tagIds = DirectiveUtils.getLongArray(PARAM_IDS, params);
		List<TagBean> tags = jsonToList(goodsExtendHessian.getTagList(tagIds), TagBean.class);
		renderParamToBody("tagList", tags, env, body);
	}

}
